﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.Entities.Properties;

namespace Workflows.Components.Entities.Collapses
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class MergeCollapseComponent:WorkflowComponentBase
    {
        #region Overrides of WorkflowComponentBase

        private MergeCollapseInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get { return _Instruction; }
            set { _Instruction = (MergeCollapseInstruction) value; }
        }

        private MergeCollapseOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get { return _Output; }
            set { _Output = (MergeCollapseOutput) value; }
        }

        #endregion

        #region props
        /// <summary></summary>
        public string ConnStr
        {
            get
            {
                return this._Instruction.ConnStr;
            }
            set
            {
                this._Instruction.ConnStr = value;
            }
        }

        /// <summary></summary>
        public string SchemaName
        {
            get
            {
                return this._Instruction.SchemaName;
            }
            set
            {
                this._Instruction.SchemaName = value;
            }
        }

        /// <summary></summary>
        public string CollapseOutputTablePrefix
        {
            get
            {
                return this._Instruction.CollapseOutputTablePrefix;
            }
            set
            {
                this._Instruction.CollapseOutputTablePrefix = value;
            }
        }

        /// <summary></summary>
        public string CollapseMappingTablePrefix
        {
            get
            {
                return this._Instruction.CollapseMappingTablePrefix;
            }
            set
            {
                this._Instruction.CollapseMappingTablePrefix = value;
            }
        }

        /// <summary></summary>
        public int PartFrom
        {
            get
            {
                return this._Instruction.PartFrom;
            }
            set
            {
                this._Instruction.PartFrom = value;
            }
        }

        /// <summary></summary>
        public int PartTo
        {
            get
            {
                return this._Instruction.PartTo;
            }
            set
            {
                this._Instruction.PartTo = value;
            }
        }

        /// <summary></summary>
        public string IDField
        {
            get
            {
                return this._Instruction.IDField;
            }
            set
            {
                this._Instruction.IDField = value;
            }
        }

        /// <summary></summary>
        public List<string> DescFields
        {
            get
            {
                return this._Instruction.DescFields;
            }
            set
            {
                this._Instruction.DescFields = value;
            }
        }

        /// <summary></summary>
        public string CollapseIDField
        {
            get
            {
                return this._Instruction.CollapseIDField;
            }
            set
            {
                this._Instruction.CollapseIDField = value;
            }
        }

        /// <summary></summary>
        public string ScoreField
        {
            get
            {
                return this._Instruction.ScoreField;
            }
            set
            {
                this._Instruction.ScoreField = value;
            }
        }

        /// <summary></summary>
        public string MergeTableName
        {
            get
            {
                return this._Instruction.MergeTableName;
            }
            set
            {
                this._Instruction.MergeTableName = value;
            }
        }

        /// <summary></summary>
        public string MergeProfileFieldName
        {
            get
            {
                return this._Instruction.MergeProfileFieldName;
            }
            set
            {
                this._Instruction.MergeProfileFieldName = value;
            }
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        public MergeCollapseComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.Entity_Relations.ToString();
            this.Description = "Merge tables after collapsing partitioned entities";
            this.ComponentIcon = Resources.WindowTile;
            this.ComponentImage = Resources.WindowTile48;
            this.ComponentName = "Merge collapsed output";

            this._Instruction=new MergeCollapseInstruction(this.ComponentID,Guid.Empty,
                string.Empty,string.Empty,string.Empty,string.Empty,1,1,
                string.Empty,string.Empty,string.Empty,new List<string>(), 
                string.Empty, string.Empty);
            this._Output=new MergeCollapseOutput(this.ComponentID,Guid.Empty,string.Empty,0,0);
        }

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            MergeCollapseComponent component = (MergeCollapseComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
